package com.heiyanquan.security.validator;

import com.heiyanquan.security.service.impl.ValidatorService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author dingaolin
 * @Date: 2017/12/6 0006.
 */
public class MyConstraintValidator implements ConstraintValidator<MyConstraint,Object> {

    @Autowired
    private ValidatorService validatorService;

    @Override
    public void initialize(MyConstraint myConstraint) {
        System.out.println("my validator initial");

    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext constraintValidatorContext) {
        System.out.println(value);
        // 返回是否校验通过
        System.out.println(validatorService.isValidPass());
        return validatorService.isValidPass();
    }
}
